package com.atguigu.day08;

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;

public class Flink10_SQL_KafkaToKafka {
    public static void main(String[] args) {
        //1.获取流的执行换
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.setParallelism(1);

        //2.获取表的执行环境
        StreamTableEnvironment tableEnv = StreamTableEnvironment.create(env);

        //TODO 3.创建从kafka读数据的表
        tableEnv.executeSql("create table source_sensor (id string,ts bigint,vc int) with(" +
                "'connector' = 'kafka'," +
                "'topic' = 'topic_source_sensor'," +
                "'properties.bootstrap.servers' = 'hadoop102:9092'," +
                "'properties.group.id' = '210927'," +
                "'scan.startup.mode' = 'latest-offset'," +
                "'format' = 'csv'" +
                ")");


        //TODO 4.创建从kafka写入的表
        tableEnv.executeSql("create table sink_sensor (id string,ts bigint,vc int) with(" +
                "'connector' = 'kafka'," +
                "'topic' = 'topic_sink_sensor'," +
                "'properties.bootstrap.servers' = 'hadoop102:9092'," +
                "'format' = 'csv'" +
                ")");

        //TODO 5.将读数据的表的数据写入写数据的表（这样就完成了Topic之间的数据转移）
        tableEnv.executeSql("insert into sink_sensor select * from source_sensor where id = 'sensor_1'");
    }
}
